using MicroMsg.Common.Event;
using MicroMsg.Manager;
using MicroMsg.Storage;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
namespace MicroMsg.UI.UserContrl
{
	public class ModeGroupHeadCtrl : UserControl
	{
		private const string TAG = "ModeGroupHeadCtrl";
		public ModeGroupHeadCtrlKind mKind;
		public static DependencyProperty mContactProperty = DependencyProperty.Register("mContact", typeof(Contact), typeof(ModeGroupHeadCtrl), new PropertyMetadata(null, new PropertyChangedCallback(ModeGroupHeadCtrl.OnmContactPropertyChanged)));
		private bool mBIsFirstLoaded = true;
		private EventWatcher mWatchxxx;
		private object mObjectWatcher = new object();
		private BitmapImage mBitImgTag;
		private bool mBIsTagShown;
		internal ContactHeadCtrl headCtrl;
		internal ClickableLayout btnImgTag;
		internal Image imgTag;
		private bool _contentLoaded;
		public event MMStandardUIEvent mItemClick;
		public event MMStandardUIEvent mTagClick;
		public Contact mContact
		{
			get
			{
				return (Contact)base.GetValue(ModeGroupHeadCtrl.mContactProperty);
			}
			set
			{
				base.SetValue(ModeGroupHeadCtrl.mContactProperty, value);
			}
		}
		public ModeGroupHeadCtrl()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.Control_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.Control_Unloaded));
		}
		private static void OnmContactPropertyChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_Property() == ModeGroupHeadCtrl.mContactProperty)
			{
				(dependencyObject_0 as ModeGroupHeadCtrl).mContactPropertyChanged(dependencyPropertyChangedEventArgs_0);
			}
		}
		private void mContactPropertyChanged(DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_OldValue() != dependencyPropertyChangedEventArgs_0.get_NewValue())
			{
				this.RefreshItem();
			}
		}
		private void Control_Loaded(object sender, RoutedEventArgs e)
		{
		}
		private void Control_Unloaded(object sender, RoutedEventArgs e)
		{
		}
		private void registerEvent()
		{
			if (this.mWatchxxx == null)
			{
				this.mWatchxxx = new EventWatcher(this.mObjectWatcher, null, new EventHandlerDelegate(this.Onxxx));
				EventCenter.registerEventWatcher(EventConst.ON_STORAGE_CONTACT_ADD, this.mWatchxxx);
			}
		}
		private void unRegisterEvent()
		{
			if (this.mWatchxxx != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_STORAGE_CONTACT_ADD, this.mWatchxxx);
				this.mWatchxxx = null;
			}
		}
		private void Onxxx(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs == null)
			{
				return;
			}
		}
		private void LayoutRoot_Click(object sender, object object_0)
		{
			if (this.mItemClick != null)
			{
				this.mItemClick(this, this.mContact);
			}
		}
		private void btnImgTag_Click(object sender, RoutedEventArgs e)
		{
			if (this.mTagClick != null)
			{
				this.mTagClick(this, this.mContact);
			}
		}
		public void RefreshItem()
		{
			this.headCtrl.mContact = this.mContact;
		}
		public void SetImgTagSrc(BitmapImage bitmapImage_0)
		{
			if (this.mBIsTagShown)
			{
				this.imgTag.set_Source(bitmapImage_0);
				this.mBitImgTag = null;
				return;
			}
			this.mBitImgTag = bitmapImage_0;
			base.UpdateLayout();
		}
		public void ShowTag()
		{
			this.mBIsTagShown = true;
			if (this.mBitImgTag != null)
			{
				this.imgTag.set_Source(this.mBitImgTag);
				this.mBitImgTag = null;
				base.UpdateLayout();
			}
			this.btnImgTag.set_Visibility(0);
		}
		public void HideTag()
		{
			this.mBIsTagShown = false;
			this.btnImgTag.set_Visibility(1);
		}
		public void SetContact(Contact contact_0)
		{
			this.mContact = contact_0;
		}
		public void SetContact(string strUser)
		{
			Contact contact = StorageMgr.contact.method_0(strUser);
			if (contact != null)
			{
				this.mContact = contact;
				return;
			}
			contact = new Contact
			{
				strUsrName = strUser,
				nImgFlag = 4u
			};
			this.mContact = contact;
		}
		public static ModeGroupHeadCtrl GetOnItem()
		{
			return new ModeGroupHeadCtrl();
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Contact/ModeGroupHeadCtrl.xaml", 2));
			this.headCtrl = (ContactHeadCtrl)base.FindName("headCtrl");
			this.btnImgTag = (ClickableLayout)base.FindName("btnImgTag");
			this.imgTag = (Image)base.FindName("imgTag");
		}
	}
}
